611B - New Year and Old Property - CodeForces Solution


bitmasks brute force implementation *1300

Please click on ads to support us..

Python Code:

l=[]
for i in range(2,100):
    k=1
    while(2**i-1-k>0 and k<2**(i-1)):
        l.append((2**i)-1-k)
        k*=2

n,m=map(int, input().split())
nb=0
for j in l:
    if (j>=n) and (j<=m) :
        nb+=1
print(nb)

C++ Code:

#include<bits/stdc++.h>
#define int unsigned long long
#define fa(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
#define bp pop_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define Utaval  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
//int arr[200010][18];
vector<int>v;
void bina(int n,int ind){
    for(int i=0;i<=ind;i++){
        int numbery= n-(int)pow(2,i);
        v.pb(numbery);
    }
}
void solve(){
    int a,b,ans=0;
    cin>>a>>b;
    fa(i,0,v.size()){
        if(v[i]>=a && v[i]<=b)ans++;
    }
    cout<<ans<<endl;
}
signed main()
{
    Utaval;
    long long t=1;
    //cin>>t;
    for(int i=1;i<=64;i++){
        int ans = pow(2,i+1)-1;
        bina(ans,i-1);
    }
    sort(v.begin(),v.end());
    while(t--)
    solve();
}
		 	 	  	 	    	 			     	   		


Comments

Submit
0 Comments
More Questions

688B - Lovely Palindromes
66B - Petya and Countryside
1557B - Moamen and k-subarrays
540A - Combination Lock
1553C - Penalty
1474E - What Is It
1335B - Construct the String
1004B - Sonya and Exhibition
1397A - Juggling Letters
985C - Liebig's Barrels
115A - Party
746B - Decoding
1424G - Years
1663A - Who Tested
1073B - Vasya and Books
195B - After Training
455A - Boredom
1099A - Snowball
1651D - Nearest Excluded Points
599A - Patrick and Shopping
237A - Free Cash
1615B - And It's Non-Zero
1619E - MEX and Increments
34B - Sale
1436A - Reorder
1363C - Game On Leaves
1373C - Pluses and Minuses
1173B - Nauuo and Chess
318B - Strings of Power
1625A - Ancient Civilization